#include <bits/stdc++.h>
using namespace std;
struct Node
{ 
    int data;
    int l, r;
} node[31];

void postOrder(int d)
{ 
    if (node[d].l != 0)
        postOrder(node[d].l);
    if (node[d].r != 0)
        postOrder(node[d].r);
    cin >> node[d].data;
}
int main()
{ 
    int N;
    cin >> N;
    for (int i = 1; i <= N; ++i)
    { 
        if (i * 2 <= N)
            node[i].l = i * 2;
        if (i * 2 + 1 <= N)
            node[i].r = i * 2 + 1;
    }
    postOrder(1);
    cout << node[1].data;
    for (int i = 2; i <= N; ++i)
        cout << " " << node[i].data;
    return 0;
}